<!--
 * @Author: Vi卡农
 * @Date: 2020-04-02 11:27:51
 * @LastEditTime: 2020-05-12 17:17:25
 * @Description: --客源公共池列表
 * @FilePath: \cshf_admin\src\views\modules\resource\resourcecustomer.vue
 -->
<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-customer__customerhouseinfo}">
      <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
        <el-row>
          <el-col :span="20">
            <el-form-item>
              类型：
              <el-select v-model="dataForm.customerType" class="FormSelect" clearable>
                <el-option label="写租" value="1"></el-option>
                <el-option label="写买" value="2"></el-option>
                <el-option label="住租" value="3"></el-option>
                <el-option label="住买" value="4"></el-option>
                <el-option label="商租" value="5"></el-option>
                <el-option label="商买" value="6"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item>
              交易：
              <el-select v-model="dataForm.transactionType" class="FormSelect" clearable>
                <el-option label="求购" value="0"></el-option>
                <el-option label="求租" value="1"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item>
              状态：
              <ren-select
                v-model="dataForm.state"
                dict-type="customerState"
                class="FormSelect"
                clearable
              ></ren-select>
            </el-form-item>
            <el-form-item>
              区域：
              <el-select
                v-model="dataForm.districtCode"
                placeholder="请选择"
                clearable
                class="FormSelect"
              >
                <el-option
                  v-for="item in this.$store.state.CityRegion"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item>
              价格：
              <el-input v-model="dataForm.prices" placeholder="最低价" class="Section_inp" clearable></el-input>
              {{' -'}}
              <el-input v-model="dataForm.pricee" placeholder="最高价" class="Section_inp" clearable></el-input>
            </el-form-item>
            <el-form-item>
              面积：
              <el-input v-model="dataForm.areas" placeholder="最小" class="Section_inp" clearable></el-input>
              {{' -'}}
              <el-input v-model="dataForm.areae" placeholder="最大" class="Section_inp" clearable></el-input>
            </el-form-item>
            <el-form-item>
              <el-button @click="Reset">重置</el-button>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-input
              placeholder="请输入内容"
              v-model="dataForm.search"
              class="input-with-select"
              @keyup.enter.native="getDataList"
              clearable
            >
              <el-button slot="append" icon="el-icon-search" @click="getDataList"></el-button>
            </el-input>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item>
              时间：
              <el-select
                v-model="dataForm.date"
                @change="dateSelectChange"
                class="FormSelect"
                clearable
              >
                <el-option label="自定义" value="6"></el-option>
                <el-option label="当天" value="1"></el-option>
                <el-option label="本周" value="2"></el-option>
                <el-option label="本月" value="3"></el-option>
                <el-option label="本季度" value="4"></el-option>
                <el-option label="今年" value="5"></el-option>
              </el-select>&nbsp;
              <el-date-picker
                v-model="dataForm.createDates"
                type="date"
                placeholder="开始时间"
                value-format="yyyy-MM-dd"
                style="width:136px"
                :disabled="dataForm.date!='6'"
              ></el-date-picker>
              {{' -'}}
              <el-date-picker
                v-model="dataForm.createDatee"
                type="date"
                placeholder="结束时间"
                value-format="yyyy-MM-dd"
                style="width:136px"
                :disabled="dataForm.date!='6'"
              ></el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <el-table
        v-loading="dataListLoading"
        :data="dataList"
        border
        @selection-change="dataListSelectionChangeHandle"
        style="width: 100%;"
        @row-dblclick="tableRowDbclick"
        @row-click="getPageFollow"
      >
        <el-table-column type="expand">
          <template slot-scope="props">
            <div class="houseinfoFollow">
              <el-card class="box-card FY_details" shadow="hover">
                <el-row>
                  <el-col :span="24">
                    <el-table :data="FollowTableData" class="FY_table_gj" height="175">
                      <el-table-column prop="content" label="跟进内容"></el-table-column>
                      <el-table-column prop="creatorName" label="跟进人" width="120"></el-table-column>
                      <el-table-column prop="deptName" label="跟进部门" width="120"></el-table-column>
                      <el-table-column prop="createDate" label="跟进时间" width="150"></el-table-column>
                    </el-table>
                  </el-col>
                </el-row>
              </el-card>
            </div>
          </template>
        </el-table-column>
        <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
        <el-table-column prop="id" label="编号" header-align="center" align="center">
          <template slot-scope="scope">{{"KY - "+scope.row.id.substring(scope.row.id.length-6)}}</template>
        </el-table-column>
        <el-table-column prop="customerName" label="客户姓名" header-align="center" align="center"></el-table-column>
        <el-table-column prop="transactionType" label="交易类型" header-align="center" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.transactionType==0" style="color:red">求购</span>
            <span v-else style="color:blue">求租</span>
          </template>
        </el-table-column>
        <el-table-column prop="type" label="物业类型" header-align="center" align="center">
          <template slot-scope="scope">
            <span
              :style="dictTypeColor(scope.row.type)"
            >{{ $getDictLabel("dictType", scope.row.type) }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="dictName" label="意向楼盘" header-align="center" align="center"></el-table-column>
        <el-table-column prop="districtCode" label="行政区域" header-align="center" align="center">
          <template slot-scope="scope">{{ $Dictionaries("CityRegion", scope.row.districtCode) }}</template>
        </el-table-column>
        <el-table-column
          prop="areas"
          label="面积区间（㎡）"
          header-align="center"
          align="center"
          width="120"
        >
          <template slot-scope="scope">{{scope.row.areas}} - {{scope.row.areae}}</template>
        </el-table-column>
        <el-table-column
          prop="prices"
          label="价格区间"
          header-align="center"
          align="center"
          width="120"
        >
          <template slot-scope="scope">{{scope.row.prices}} - {{scope.row.pricee}}</template>
        </el-table-column>
        <el-table-column prop="renovation" label="装修要求" header-align="center" align="center">
          <template slot-scope="scope">{{ $getDictLabel("dictRenovation", scope.row.renovation) }}</template>
        </el-table-column>

        <el-table-column prop="communication" label="沟通阶段" header-align="center" align="center">
          <template
            slot-scope="scope"
          >{{ $getDictLabel("customerCommunication", scope.row.communication) }}</template>
        </el-table-column>
        <el-table-column prop="state" label="状态" header-align="center" align="center">
          <template slot-scope="scope">{{ $getDictLabel("customerState", scope.row.state) }}</template>
        </el-table-column>
        <el-table-column prop="source" label="客户来源" header-align="center" align="center">
          <template slot-scope="scope">{{ $getDictLabel("customerSource", scope.row.source) }}</template>
        </el-table-column>
        <el-table-column prop="maintainName" label="经纪人" header-align="center" align="center"></el-table-column>
        <el-table-column prop="createDate" label="录入时间" header-align="center" align="center">
          <template slot-scope="scope">
            <span>{{scope.row.createDate!=null?scope.row.createDate.substring(0,10):scope.row.createDate}}</span>
          </template>
        </el-table-column>
        <el-table-column
          :label="$t('handle')"
          fixed="right"
          header-align="center"
          align="center"
          width="80"
        >
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="getResourceCustomer(scope.row)">拾取</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- <div class="ZWbox2"></div> -->
      <!-- <div class="paginationBox2" :style="'width:'+autoWidthVal">
        <el-card class="box-card martop15 FY_details" shadow="hover">
          <el-table :data="FollowTableData" class="FY_table_gj" height="175">
            <el-table-column prop="content" label="跟进内容"></el-table-column>
            <el-table-column prop="creatorName" label="跟进人" width="120"></el-table-column>
            <el-table-column prop="deptName" label="跟进部门" width="120"></el-table-column>
            <el-table-column prop="createDate" label="跟进时间" width="150"></el-table-column>
          </el-table>
        </el-card>
        <el-pagination
          :current-page="page"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="limit"
          :total="total"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="pageSizeChangeHandle"
          @current-change="pageCurrentChangeHandle"
        ></el-pagination>
      </div>-->
      <div class="paginationBox">
        <el-pagination
          :current-page="page"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="limit"
          :total="total"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="pageSizeChangeHandle"
          @current-change="pageCurrentChangeHandle"
        ></el-pagination>
      </div>
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from "@/mixins/view-module";
export default {
  mixins: [mixinViewModule],
  data() {
    return {
      mixinViewModuleOptions: {
        getDataListURL: "/resource/resourcecustomer/housePage",
        getDataListIsPage: true
      },
      dataForm: {
        id: "",
        customerType: "",
        transactionType: "",
        state: "",
        districtCode: "",
        prices: "",
        pricee: "",
        areas: "",
        areae: "",
        createDates: "",
        createDatee: "",
        date: "6",
        customerName: "",
        search: "",
        dictId: "",
        customerId: ""
      },
      autoWidthVal: "",
      FollowTableData: []
    };
  },
  components: {
    // AddOrUpdate
  },
  computed: {
    zjName: {
      get: function() {
        this.addUrl;
        var myComponent = () => import(`${this.addUrl}`);
        return myComponent;
      }
    }
  },
  created() {
    let _this = this;
    this.autoWidth();
    window.onresize = function() {
      _this.autoWidth();
    };
  },
  methods: {
    Reset() {
      this.dataForm = {
        id: "",
        customerType: "",
        transactionType: "",
        state: "",
        districtCode: "",
        prices: "",
        pricee: "",
        areas: "",
        areae: "",
        createDates: "",
        createDatee: "",
        date: "6",
        customerName: "",
        search: "",
        dictId: this.$route.query.dictId ? this.$route.query.dictId : ""
      };
    },

    autoWidth() {
      let w = document.documentElement.scrollWidth || document.body.scrollWidth;
      this.autoWidthVal = w - 270 + "px";
    },
    //获取客源跟进记录
    getPageFollow(row) {
      let _this = this;
      this.$http
        .get(`/resource/resourcecustomer/followPage`, {
          params: {
            page: 1,
            limit: 50,
            customerId: row.id,
            customerType: row.customerType
          }
        })
        .then(({ data: res }) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg);
          }
          _this.FollowTableData = res.data.list;
        })
        .catch(() => {});
    },

    // 日期方式切换
    dateSelectChange(val) {
      if (val != "6") {
        this.dataForm.createDates = "";
        this.dataForm.createDatee = "";
      }
    },
    //行双击
    // tableRowDbclick(row) {
    //   this.$router.push({
    //     name: "customerPage",
    //     query: {
    //       ID: row.id,
    //       customerType: row.customerType
    //     }
    //   });
    // },
    //拾取
    getResourceCustomer(row) {
      let _this = this;
      this.$http
        .put(
          "/resource/resourcecustomer/getResourceCustomer",
          {},
          {
            params: {
              id: row.id,
              customerType: row.customerType
            }
          }
        )
        .then(({ data: res }) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg);
          }
          this.$message.success("成功！");
        })
        .catch(() => {});
    }
  },
  watch: {
    dataForm: {
      handler(nowVal, oldVal) {
        this.getDataList();
      },
      deep: true
    }
  }
};
</script>
<style lang="scss" scoped>
.FormSelect {
  width: 90px;
}
.Section_inp {
  width: 80px !important;
}
.el-form--inline .el-form-item {
  margin-right: 7px;
}
.el-checkbox {
  margin-right: 10px;
}
.el-form-item--mini.el-form-item,
.el-form-item--small.el-form-item {
  margin-bottom: 7px;
}
</style>